<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>

<html xmlns="http://www.w3.org/1999/xhtml" lang="">

	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">

		<title><?php echo C('WEB_TITLE');?></title>

		<link rel="stylesheet" type="text/css" href="/Public/css/common.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/js/layui/css/layui.css" media="all"/>

		<link rel="stylesheet" type="text/css" href="/Public/index/css/index.css"/>

		<link rel="stylesheet" type="text/css" href="/Public/index/css/style.css"/>

		<link rel="stylesheet" href="<?php echo C('PC_ICON_HTTP');?>">

		<script type="text/javascript" >

			const moduleName = "<?php echo (MODULE_NAME); ?>";

		</script>

        <link rel="stylesheet" href="/Public/js/viewer/css/viewer.min.css">

		<script type="text/javascript" src="/Public/js/jquery-1.9.1.min.js"></script>

		<script type="text/javascript" src="/Public/js/jquery-ui.min.js"></script>

		<script type="text/javascript" src="/Public/js/cookie/jquery.cookie.js"></script>

		<script type="text/javascript" src="/Public/js/lang/<?php echo (getStrToLower(cookie('think_language'))); ?>.js"></script>

		<script type="text/javascript" src="/Public/js/colorpicker.js"></script>

		<script type="text/javascript" src="/Public/js/layer/layer.js"></script>

		<script type="text/javascript" src="/Public/js/layui/layui.js"></script>

		<script type="text/javascript" src="/Public/js/jquery.nicescroll.js"></script>

		<script type="text/javascript" src="/Public/js/clipboard.min.js"></script>

        <script type="text/javascript" src="/Public/js/feeldesk.js"></script>
<!--
		<script type="text/javascript" src="/Public/js/signature/flashcanvas.js"></script>

		<script type="text/javascript" src="/Public/js/signature/signature.min.js"></script>
-->

        <script type="text/javascript" src="/Public/index/js/index.js"></script>

<!--		<script type="text/javascript" src="/Public/js/Lodop/LodopFuncs.js"></script>-->

		<script type="text/javascript" src="/Public/js/xm-select/xm-select.js"></script>

	</head>

    <body>


    <div class="fd-right-main">

        <div class="fd-body">

            <div class="fd-main">

                <div class="fd-right-top">

                    <span class="crumb">

                        <?php if(CONTROLLER_NAME != 'Census' && CONTROLLER_NAME != 'Ticket'): $href = '/'.CONTROLLER_NAME.'/index'; ?>

                        <?php else: ?>

                            <?php $href = 'javascript:'; endif; ?>

                        <a href="<?php echo ($href); ?>"><?php echo L('ROLE_MANAGER');?></a>

                        <i class="layui-icon">&#xe623;</i>

                        <a class="black6"><cite><?php echo getViewName();?></cite></a>

                        

                    </span>

                    

                    

                </div>

                

    <div class="feeldesk-list">

        <div class="feeldesk-list-header clearfix">

            <div class="header-left">

                <?php if(!empty($data["auth"]["create"])): ?><a href="javascript:" onclick="openFormWindow(this,'<?php echo U('create');?>')" class="createBtn" title="<?php echo L('NEW_ROLE');?>">
                        <i class="iconfont icon-xinzeng"></i><?php echo L('NEW_ROLE');?>
                    </a><?php endif; ?>

            </div>

            <div class="header-right">

                <form action="<?php echo ($controllerAndAction); ?>" method="get" class="fr">

                    <div class="compact-search">

                        <i class="iconfont icon-search"></i>

                        <input type="text" name="keyword" value="<?php echo ($keyword); ?>" placeholder="<?php echo L('ROLE_NAME');?>"/>

                        <a href="javascript:" class="searchBtn"><?php echo L('SEARCH');?></a>

                    </div>

                </form>

            </div>

        </div>

        <div class="feeldesk-list-content">

            <div class="feeldesk-list-main">

                <table class="layui-table" lay-skin="nob">

                    <thead>

                        <tr>

                            <th class="left"><?php echo L('ROLE_NAME');?></th>

                            <th><?php echo L('STATUS');?></th>

                            <th><?php echo L('CREATE_TIME');?></th>

                            <th><?php echo L('OPERATION');?></th>

                        </tr>

                    </thead>

                    <tbody>

                        <?php if(empty($data["roles"])): ?><tr class="nodata center"><td colspan="11"><?php echo L('NO_DATA');?></td></tr>

                        <?php else: ?>

                            <?php if(is_array($data["roles"])): $i = 0; $__LIST__ = $data["roles"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>

                                    <td class="left">

                                        <span><?php echo ($vo["role_name"]); ?></span>

                                        <?php if(($vo["is_supper"]) == "20"): ?><i class="iconfont icon-admin"></i><?php endif; ?>

                                        <?php if(($vo["is_default"]) == "10"): ?><i class="iconfont icon-moren"></i><?php endif; ?>

                                    </td>

                                    <td>

                                        <?php if(($vo["closed"]) == "0"): ?><span class="open-status enable"><?php echo L('ENABLE');?></span>

                                        <?php else: ?>

                                            <span class="open-status disable"><?php echo L('DISABLE');?></span><?php endif; ?>

                                    </td>

                                    <td><?php echo (getDates($vo["create_time"])); ?></td>

                                    <td class="feeldesk-list-operate">

                                        <i class="iconfont icon-dian"></i>

                                        <div class="operate-panel hidden">

                                            <?php $id = encrypt($vo['role_id'],'ROLE'); ?>

                                            <?php if(!empty($data["auth"]["editor"])): ?><a href='javascript:' title="<?php echo L('EDITOR');?>" onclick="openFormWindow(this,'<?php echo U('editor',['id'=>$id]);?>')">
                                                    <?php echo L('EDITOR');?>
                                                </a><?php endif; ?>

                                            <?php if($data['auth']['auth']): ?><a href="<?php echo U('auth',['id'=>$id]);?>"><?php echo L('ROLE_AUTH');?></a><?php endif; ?>

                                            <?php if($data['auth']['delete'] && $vo['closed'] == 1 && $vo['is_supper'] != 20): ?><a href="<?php echo U('delete',['id'=>$id]);?>" load="del-role"><?php echo L('DELETE');?></a><?php endif; ?>

                                            <?php if(!empty($data["auth"]["member"])): ?><a href="<?php echo U('Member/index',['role_id'=>$vo['role_id']]);?>"><?php echo L('VIEW_USER');?></a><?php endif; ?>

                                            <a href="javascript:" data-value="<?php echo ($vo["role_id"]); ?>" data-name="<?php echo ($vo["role_name"]); ?>" class="assign-user"><?php echo L('ASSIGN_USER');?></a>

                                        </div>

                                    </td>

                                </tr><?php endforeach; endif; else: echo "" ;endif; endif; ?>

                    </tbody>

                </table>

            </div>

        </div>

        <?php if(($data["auth"]["delete"]) > "0"): ?><div class="groupItem hidden" id="role-item">

                <form action="" class="layui-form pd20" lay-filter="role">

                    <input type="hidden" name="role[role_id]" value="" id="roleId"/>

                    <div class="mb10"><?php echo L('SELECT_TRANSFER_ROLE');?></div>

                    <div class="layui-form-item">

                        <div class="layui-input-block ml0">

                            <select name="role[update_role_id]" lay-search id="roleItem"></select>

                        </div>

                    </div>

                    <div class="layui-form-item">

                        <div class="layui-input-block ml0 center">

                            <a href="javascript:" class="layui-btn" lay-submit lay-filter="deleteRoleForm"><?php echo L('SURE');?></a>

                        </div>

                    </div>

                </form>

            </div><?php endif; ?>

    </div>

    <?php if(($data["auth"]["delete"]) > "0"): ?><script type="text/javascript">

            $(function ()
            {
                layui.use('form',function ()
                {
                    var form = layui.form;

                    var roles = JSON.parse('<?php echo ($data["roleJson"]); ?>');

                    $("a[load='del-role']").on('click',function(e)
                    {
                        e.preventDefault();

                        var role_id = $(this).attr('href').split('/')[4];

                        $('#roleId').val(role_id);

                        var option = "<option value=''><?php echo L('SELECT_ROLE');?></option>";

                        $.each(roles,function (k,v)
                        {
                            if(role_id != v.role_id && v.closed == 0)
                            {
                                option += "<option value='"+v.role_id+"'>"+v.role_name+"</option>";
                            }
                        });

                        $('#roleItem').html(option);

                        form.render('select','role');

                        layer.open(
                        {
                            type: 1,
                            offset:['100px'],
                            area:['400px','500px'],
                            content: $('#role-item')
                        });
                    });

                    form.on('submit(deleteRoleForm)',function (data)
                    {
                        $.post('/Role/delete',$(data.form).serialize(),function(data)
                        {
                            if(data.errcode != 0)
                            {
                                feelDeskAlert(data.msg);
                            }
                            else
                            {
                                data.isReload = 1;

                                feelDeskAlert(data.msg,data);
                            }
                        })
                    })
                })
            })

        </script><?php endif; ?>

    <div class="assign-user-pannel hidden" id="assignUserPannel">

        <header>

            <span class="move-element"><?php echo L('ASSIGN_USER');?></span>

            <div class="assign-search">

                <i class="iconfont icon-search"></i>

                <input type="text" name="keyword" placeholder="<?php echo L('ASSIGN_SEARCH');?>" autocomplete="off" id="assignSearch"/>

            </div>

            <i class="iconfont icon-close1 assign-closed"></i>

        </header>

        <form action="" class="layui-form" id="assignUserForm">

            <div class="assign-user-main">

                <div class="assign-main-header">

                    <span><?php echo L('ROLE_NAME');?>：</span><span class="green3" id="assginRoleName"></span>

                    <a href="javascript:" class="assign-user-submit" id="assignSubmit"><?php echo L('SAVE');?></a>

                </div>

                <div class="item-header">

                    <ul><li><?php echo L('CHOOSE');?></li><li><?php echo L('NAME');?></li><li><?php echo L('MOBILE');?></li><li><?php echo L('EMAIL');?></li></ul>

                </div>

                <div id="assignUserItem"></div>

            </div>

        </form>

    </div>

    <script type="text/javascript">

        $(function()
        {
            layui.use(['form','flow'], function ()
            {
                var form = layui.form;

                var flow = layui.flow;

                $('.assign-user').unbind('click').on('click', function ()
                {
                    var value = $(this).data('value');

                    var name = $(this).data('name');

                    layer.open(
                    {
                        title: false,
                        type: 1,
                        content: $('#assignUserPannel'),
                        closeBtn: 0,
                        skin: 'assign-members-window',
                        offset: ['10%'],
                        move: $('.move-element'),
                        moveOut: true,
                        moveType: 0,
                        area: ['600px', '60%'],
                        shade: [0.3, '#333'],
                        success: function (layero, index)
                        {
                            $('#assginRoleName').text(name);

                            var searchWidth = parseFloat($('.assign-search').width() / 2 + 100);

                            $('.assign-search').css({left:"calc(50% - "+searchWidth+"px)"});

                            flow.load(
                            {
                                elem: '#assignUserItem',
                                end: "<?php echo L('NO_MORE');?>",
                                done: function (page, next)
                                {
                                    $.post("/Role/index?request=assign&p=" + page, function (data)
                                    {
                                        var lis = [];

                                        var item = '';

                                        $.each(data.data,function(k,v)
                                        {
                                            var isChecked = '';

                                            if(v.role_id == value) isChecked = 'checked';

                                            item += "<div class='assign-user-item'><ul>" +
                                                    "<li><input type='checkbox' name='userId[]' value='"+v.member_id+"' lay-skin='primary' "+isChecked+"/></li>" +
                                                    "<li>"+ v.name+"</li><li>"+ v.mobile+"</li><li>"+ v.email+"</li></ul></div>";

                                        });

                                        lis.push(item);

                                        next(lis.join(''), page < data.pages);

                                        form.render('checkbox');

                                    },'JSON');
                                }
                            });

                            $('.assign-closed').on('click', function ()
                            {
                                layer.close(index);

                                $('#assignUserItem').html('');
                            });

                            $('#assignSubmit').unbind('click').on('click', function (e)
                            {
                                e.stopPropagation();

                                var loading = layer.load(2, {offset: ['15vw']});

                                $.post("<?php echo U('Role/index');?>?request=submit&id=" + value, $('#assignUserForm').serialize(), function (data)
                                {
                                    if (data.errcode == 0)
                                    {
                                        feelDeskAlert(data.msg,data);
                                    }
                                    else
                                    {
                                        feelDeskAlert(data.msg);
                                    }

                                    layer.close(loading);

                                }, 'JSON');
                            })
                        }
                    });


                    $('#assignSearch').keyup(function ()
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            $('#assignUserItem').find('.assign-user-item').hide().filter(":contains('" + ($(this).val()) + "')").show();

                            $('#assignUserForm').find('.layui-flow-more').fadeOut('fast');
                        }
                        else
                        {
                            $('#assignUserItem').find('.assign-user-item').show();

                            $('#assignUserForm').find('.layui-flow-more').fadeIn('fast');
                        }
                    });
                });
            })
        });

    </script>



            </div>

        </div>

    </div>

    </body>

</html>